
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.phonopy &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.phonopy</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.phonopy</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Module for interfacing with phonopy, see https://atztogo.github.io/phonopy/</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">pymatgen.core</span> <span class="kn">import</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.phonon.bandstructure</span> <span class="kn">import</span> <span class="n">PhononBandStructureSymmLine</span><span class="p">,</span> \
    <span class="n">PhononBandStructure</span>
<span class="kn">from</span> <span class="nn">pymatgen.phonon.dos</span> <span class="kn">import</span> <span class="n">PhononDos</span><span class="p">,</span> <span class="n">CompletePhononDos</span>
<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span>
<span class="kn">from</span> <span class="nn">monty.dev</span> <span class="kn">import</span> <span class="n">requires</span>

<span class="kn">from</span> <span class="nn">pymatgen.symmetry.bandstructure</span> <span class="kn">import</span> <span class="n">HighSymmKpath</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">phonopy</span> <span class="kn">import</span> <span class="n">Phonopy</span>
    <span class="kn">from</span> <span class="nn">phonopy.structure.atoms</span> <span class="kn">import</span> <span class="n">PhonopyAtoms</span>
    <span class="kn">from</span> <span class="nn">phonopy.file_IO</span> <span class="kn">import</span> <span class="n">write_disp_yaml</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">Phonopy</span> <span class="o">=</span> <span class="kc">None</span>


<div class="viewcode-block" id="get_pmg_structure"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_pmg_structure">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy not installed!&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_pmg_structure</span><span class="p">(</span><span class="n">phonopy_structure</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Convert a PhonopyAtoms object to pymatgen Structure object.</span>

<span class="sd">    Args:</span>
<span class="sd">        phonopy_structure (PhonopyAtoms): A phonopy structure object.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">lattice</span> <span class="o">=</span> <span class="n">phonopy_structure</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span>
    <span class="n">frac_coords</span> <span class="o">=</span> <span class="n">phonopy_structure</span><span class="o">.</span><span class="n">get_scaled_positions</span><span class="p">()</span>
    <span class="n">symbols</span> <span class="o">=</span> <span class="n">phonopy_structure</span><span class="o">.</span><span class="n">get_chemical_symbols</span><span class="p">()</span>
    <span class="n">masses</span> <span class="o">=</span> <span class="n">phonopy_structure</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
    <span class="n">mms</span> <span class="o">=</span> <span class="n">phonopy_structure</span><span class="o">.</span><span class="n">get_magnetic_moments</span><span class="p">()</span>
    <span class="n">mms</span> <span class="o">=</span> <span class="n">mms</span> <span class="ow">or</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">Structure</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">frac_coords</span><span class="p">,</span>
                     <span class="n">site_properties</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;phonopy_masses&quot;</span><span class="p">:</span> <span class="n">masses</span><span class="p">,</span>
                                      <span class="s2">&quot;magnetic_moments&quot;</span><span class="p">:</span> <span class="n">mms</span><span class="p">})</span></div>


<div class="viewcode-block" id="get_phonopy_structure"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_phonopy_structure">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy not installed!&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_phonopy_structure</span><span class="p">(</span><span class="n">pmg_structure</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Convert a pymatgen Structure object to a PhonopyAtoms object.</span>

<span class="sd">    Args:</span>
<span class="sd">        pmg_structure (pymatgen Structure): A Pymatgen structure object.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">pmg_structure</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">PhonopyAtoms</span><span class="p">(</span><span class="n">symbols</span><span class="o">=</span><span class="n">symbols</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">pmg_structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">,</span>
                        <span class="n">scaled_positions</span><span class="o">=</span><span class="n">pmg_structure</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_structure_from_dict"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_structure_from_dict">[docs]</a><span class="k">def</span> <span class="nf">get_structure_from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Extracts a structure from the dictionary extracted from the output</span>
<span class="sd">    files of phonopy like phonopy.yaml or band.yaml.</span>
<span class="sd">    Adds &quot;phonopy_masses&quot; in the site_properties of the structures.</span>
<span class="sd">    Compatible with older phonopy versions.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">species</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">frac_coords</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">masses</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span> <span class="s1">&#39;points&#39;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;points&#39;</span><span class="p">]:</span>
            <span class="n">species</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;symbol&#39;</span><span class="p">])</span>
            <span class="n">frac_coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;coordinates&#39;</span><span class="p">])</span>
            <span class="n">masses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;mass&#39;</span><span class="p">])</span>
    <span class="k">elif</span> <span class="s1">&#39;atoms&#39;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;atoms&#39;</span><span class="p">]:</span>
            <span class="n">species</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;symbol&#39;</span><span class="p">])</span>
            <span class="n">frac_coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;position&#39;</span><span class="p">])</span>
            <span class="n">masses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;mass&#39;</span><span class="p">])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The dict does not contain structural information&#39;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">Structure</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice&#39;</span><span class="p">],</span> <span class="n">species</span><span class="p">,</span> <span class="n">frac_coords</span><span class="p">,</span>
                     <span class="n">site_properties</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;phonopy_masses&quot;</span><span class="p">:</span> <span class="n">masses</span><span class="p">})</span></div>


<div class="viewcode-block" id="eigvec_to_eigdispl"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.eigvec_to_eigdispl">[docs]</a><span class="k">def</span> <span class="nf">eigvec_to_eigdispl</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">frac_coords</span><span class="p">,</span> <span class="n">mass</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Converts a single eigenvector to an eigendisplacement in the primitive cell</span>
<span class="sd">    according to the formula::</span>

<span class="sd">        exp(2*pi*i*(frac_coords \\dot q) / sqrt(mass) * v</span>

<span class="sd">    Compared to the modulation option in phonopy, here all the additional</span>
<span class="sd">    multiplicative and phase factors are set to 1.</span>

<span class="sd">    Args:</span>
<span class="sd">        v: the vector that should be converted. A 3D complex numpy array.</span>
<span class="sd">        q: the q point in fractional coordinates</span>
<span class="sd">        frac_coords: the fractional coordinates of the atom</span>
<span class="sd">        mass: the mass of the atom</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="mi">2</span><span class="n">j</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">frac_coords</span><span class="p">,</span> <span class="n">q</span><span class="p">))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">mass</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">c</span> <span class="o">*</span> <span class="n">v</span></div>


<div class="viewcode-block" id="get_ph_bs_symm_line_from_dict"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_ph_bs_symm_line_from_dict">[docs]</a><span class="k">def</span> <span class="nf">get_ph_bs_symm_line_from_dict</span><span class="p">(</span><span class="n">bands_dict</span><span class="p">,</span> <span class="n">has_nac</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">labels_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Creates a pymatgen PhononBandStructure object from the dictionary</span>
<span class="sd">    extracted by the band.yaml file produced by phonopy. The labels</span>
<span class="sd">    will be extracted from the dictionary, if present. If the &#39;eigenvector&#39;</span>
<span class="sd">    key is found the eigendisplacements will be calculated according to the</span>
<span class="sd">    formula::</span>

<span class="sd">        exp(2*pi*i*(frac_coords \\dot q) / sqrt(mass) * v</span>

<span class="sd">    and added to the object.</span>

<span class="sd">    Args:</span>
<span class="sd">        bands_dict: the dictionary extracted from the band.yaml file</span>
<span class="sd">        has_nac: True if the data have been obtained with the option</span>
<span class="sd">            --nac option. Default False.</span>
<span class="sd">        labels_dict: dict that links a qpoint in frac coords to a label.</span>
<span class="sd">            Its value will replace the data contained in the band.yaml.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">structure</span> <span class="o">=</span> <span class="n">get_structure_from_dict</span><span class="p">(</span><span class="n">bands_dict</span><span class="p">)</span>

    <span class="n">qpts</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">frequencies</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">eigendisplacements</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">phonopy_labels_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">bands_dict</span><span class="p">[</span><span class="s1">&#39;phonon&#39;</span><span class="p">]:</span>
        <span class="n">q</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s1">&#39;q-position&#39;</span><span class="p">]</span>
        <span class="n">qpts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
        <span class="n">bands</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">eig_q</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">p</span><span class="p">[</span><span class="s1">&#39;band&#39;</span><span class="p">]:</span>
            <span class="n">bands</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="s1">&#39;frequency&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="s1">&#39;eigenvector&#39;</span> <span class="ow">in</span> <span class="n">b</span><span class="p">:</span>
                <span class="n">eig_b</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">eig_a</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="s1">&#39;eigenvector&#39;</span><span class="p">]):</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">complex</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                        <span class="n">v</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">eig_a</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">eig_a</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">1</span><span class="n">j</span>
                    <span class="n">eig_b</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">eigvec_to_eigdispl</span><span class="p">(</span>
                        <span class="n">v</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">structure</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">,</span>
                        <span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="p">[</span><span class="s1">&#39;phonopy_masses&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                <span class="n">eig_q</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">eig_b</span><span class="p">)</span>
        <span class="n">frequencies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bands</span><span class="p">)</span>
        <span class="k">if</span> <span class="s1">&#39;label&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span>
            <span class="n">phonopy_labels_dict</span><span class="p">[</span><span class="n">p</span><span class="p">[</span><span class="s1">&#39;label&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s1">&#39;q-position&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">eig_q</span><span class="p">:</span>
            <span class="n">eigendisplacements</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">eig_q</span><span class="p">)</span>

    <span class="n">qpts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">qpts</span><span class="p">)</span>
    <span class="c1"># transpose to match the convention in PhononBandStructure</span>
    <span class="n">frequencies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">frequencies</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">eigendisplacements</span><span class="p">:</span>
        <span class="n">eigendisplacements</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">eigendisplacements</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

    <span class="n">rec_latt</span> <span class="o">=</span> <span class="n">Lattice</span><span class="p">(</span><span class="n">bands_dict</span><span class="p">[</span><span class="s1">&#39;reciprocal_lattice&#39;</span><span class="p">])</span>

    <span class="n">labels_dict</span> <span class="o">=</span> <span class="n">labels_dict</span> <span class="ow">or</span> <span class="n">phonopy_labels_dict</span>

    <span class="n">ph_bs</span> <span class="o">=</span> <span class="n">PhononBandStructureSymmLine</span><span class="p">(</span>
        <span class="n">qpts</span><span class="p">,</span> <span class="n">frequencies</span><span class="p">,</span> <span class="n">rec_latt</span><span class="p">,</span> <span class="n">has_nac</span><span class="o">=</span><span class="n">has_nac</span><span class="p">,</span> <span class="n">labels_dict</span><span class="o">=</span><span class="n">labels_dict</span><span class="p">,</span>
        <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">eigendisplacements</span><span class="o">=</span><span class="n">eigendisplacements</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">ph_bs</span></div>


<div class="viewcode-block" id="get_ph_bs_symm_line"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_ph_bs_symm_line">[docs]</a><span class="k">def</span> <span class="nf">get_ph_bs_symm_line</span><span class="p">(</span><span class="n">bands_path</span><span class="p">,</span> <span class="n">has_nac</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">labels_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Creates a pymatgen PhononBandStructure from a band.yaml file.</span>
<span class="sd">    The labels will be extracted from the dictionary, if present.</span>
<span class="sd">    If the &#39;eigenvector&#39;  key is found the eigendisplacements will be</span>
<span class="sd">    calculated according to the formula:</span>
<span class="sd">    \\exp(2*pi*i*(frac_coords \\dot q) / sqrt(mass) * v</span>
<span class="sd">     and added to the object.</span>

<span class="sd">    Args:</span>
<span class="sd">        bands_path: path to the band.yaml file</span>
<span class="sd">        has_nac: True if the data have been obtained with the option</span>
<span class="sd">            --nac option. Default False.</span>
<span class="sd">        labels_dict: dict that links a qpoint in frac coords to a label.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">get_ph_bs_symm_line_from_dict</span><span class="p">(</span><span class="n">loadfn</span><span class="p">(</span><span class="n">bands_path</span><span class="p">),</span> <span class="n">has_nac</span><span class="p">,</span>
                                         <span class="n">labels_dict</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_ph_dos"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_ph_dos">[docs]</a><span class="k">def</span> <span class="nf">get_ph_dos</span><span class="p">(</span><span class="n">total_dos_path</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Creates a pymatgen PhononDos from a total_dos.dat file.</span>

<span class="sd">    Args:</span>
<span class="sd">        total_dos_path: path to the total_dos.dat file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span><span class="n">total_dos_path</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">PhononDos</span><span class="p">(</span><span class="n">a</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">a</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">])</span></div>


<div class="viewcode-block" id="get_complete_ph_dos"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_complete_ph_dos">[docs]</a><span class="k">def</span> <span class="nf">get_complete_ph_dos</span><span class="p">(</span><span class="n">partial_dos_path</span><span class="p">,</span> <span class="n">phonopy_yaml_path</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Creates a pymatgen CompletePhononDos from a partial_dos.dat and</span>
<span class="sd">    phonopy.yaml files.</span>
<span class="sd">    The second is produced when generating a Dos and is needed to extract</span>
<span class="sd">    the structure.</span>

<span class="sd">    Args:</span>
<span class="sd">        partial_dos_path: path to the partial_dos.dat file.</span>
<span class="sd">        phonopy_yaml_path: path to the phonopy.yaml file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span><span class="n">partial_dos_path</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">phonopy_yaml_path</span><span class="p">)</span>

    <span class="n">structure</span> <span class="o">=</span> <span class="n">get_structure_from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;primitive_cell&#39;</span><span class="p">])</span>

    <span class="n">total_dos</span> <span class="o">=</span> <span class="n">PhononDos</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>

    <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">site</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">:]):</span>
        <span class="n">pdoss</span><span class="p">[</span><span class="n">site</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">CompletePhononDos</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">total_dos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_displaced_structures"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_displaced_structures">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy not installed!&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_displaced_structures</span><span class="p">(</span><span class="n">pmg_structure</span><span class="p">,</span> <span class="n">atom_disp</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span>
                             <span class="n">supercell_matrix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">yaml_fname</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generate a set of symmetrically inequivalent displaced structures for</span>
<span class="sd">    phonon calculations.</span>

<span class="sd">    Args:</span>
<span class="sd">        pmg_structure (Structure): A pymatgen structure object.</span>
<span class="sd">        atom_disp (float): Atomic displacement. Default is 0.01 $\\AA$.</span>
<span class="sd">        supercell_matrix (3x3 array): Scaling matrix for supercell.</span>
<span class="sd">        yaml_fname (string): If not None, it represents the full path to</span>
<span class="sd">            the outputting displacement yaml file, e.g. disp.yaml.</span>
<span class="sd">        **kwargs: Parameters used in Phonopy.generate_displacement method.</span>

<span class="sd">    Return:</span>
<span class="sd">        A list of symmetrically inequivalent structures with displacements, in</span>
<span class="sd">        which the first element is the perfect supercell structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">is_plusminus</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;is_plusminus&quot;</span><span class="p">,</span> <span class="s2">&quot;auto&quot;</span><span class="p">)</span>
    <span class="n">is_diagonal</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;is_diagonal&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
    <span class="n">is_trigonal</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;is_trigonal&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>

    <span class="n">ph_structure</span> <span class="o">=</span> <span class="n">get_phonopy_structure</span><span class="p">(</span><span class="n">pmg_structure</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">supercell_matrix</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">supercell_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>

    <span class="n">phonon</span> <span class="o">=</span> <span class="n">Phonopy</span><span class="p">(</span><span class="n">unitcell</span><span class="o">=</span><span class="n">ph_structure</span><span class="p">,</span> <span class="n">supercell_matrix</span><span class="o">=</span><span class="n">supercell_matrix</span><span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">generate_displacements</span><span class="p">(</span><span class="n">distance</span><span class="o">=</span><span class="n">atom_disp</span><span class="p">,</span>
                                  <span class="n">is_plusminus</span><span class="o">=</span><span class="n">is_plusminus</span><span class="p">,</span>
                                  <span class="n">is_diagonal</span><span class="o">=</span><span class="n">is_diagonal</span><span class="p">,</span>
                                  <span class="n">is_trigonal</span><span class="o">=</span><span class="n">is_trigonal</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">yaml_fname</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">displacements</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">get_displacements</span><span class="p">()</span>
        <span class="n">write_disp_yaml</span><span class="p">(</span><span class="n">displacements</span><span class="o">=</span><span class="n">displacements</span><span class="p">,</span>
                        <span class="n">supercell</span><span class="o">=</span><span class="n">phonon</span><span class="o">.</span><span class="n">get_supercell</span><span class="p">(),</span>
                        <span class="n">filename</span><span class="o">=</span><span class="n">yaml_fname</span><span class="p">)</span>

    <span class="c1"># Supercell structures with displacement</span>
    <span class="n">disp_supercells</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">get_supercells_with_displacements</span><span class="p">()</span>
    <span class="c1"># Perfect supercell structure</span>
    <span class="n">init_supercell</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">get_supercell</span><span class="p">()</span>
    <span class="c1"># Structure list to be returned</span>
    <span class="n">structure_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">get_pmg_structure</span><span class="p">(</span><span class="n">init_supercell</span><span class="p">)]</span>

    <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">disp_supercells</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">structure_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">get_pmg_structure</span><span class="p">(</span><span class="n">c</span><span class="p">))</span>

    <span class="k">return</span> <span class="n">structure_list</span></div>


<div class="viewcode-block" id="get_phonon_dos_from_fc"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_phonon_dos_from_fc">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy is required to calculate phonon density of states&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_phonon_dos_from_fc</span><span class="p">(</span>
    <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span>
    <span class="n">supercell_matrix</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">force_constants</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">mesh_density</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">100.</span><span class="p">,</span>
    <span class="n">num_dos_steps</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">200</span><span class="p">,</span>
    <span class="o">**</span><span class="n">kwargs</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">CompletePhononDos</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Get a projected phonon density of states from phonopy force constants.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: A structure.</span>
<span class="sd">        supercell_matrix: The supercell matrix used to generate the force</span>
<span class="sd">            constants.</span>
<span class="sd">        force_constants: The force constants in phonopy format.</span>
<span class="sd">        mesh_density: The density of the q-point mesh. See the docstring</span>
<span class="sd">            for the ``mesh`` argument in Phonopy.init_mesh() for more details.</span>
<span class="sd">        num_dos_steps: Number of frequency steps in the energy grid.</span>
<span class="sd">        **kwargs: Additional kwargs passed to the Phonopy constructor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        The density of states.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">structure_phonopy</span> <span class="o">=</span> <span class="n">get_phonopy_structure</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
    <span class="n">phonon</span> <span class="o">=</span> <span class="n">Phonopy</span><span class="p">(</span>
        <span class="n">structure_phonopy</span><span class="p">,</span> <span class="n">supercell_matrix</span><span class="o">=</span><span class="n">supercell_matrix</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
    <span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">set_force_constants</span><span class="p">(</span><span class="n">force_constants</span><span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">run_mesh</span><span class="p">(</span>
        <span class="n">mesh_density</span><span class="p">,</span>
        <span class="n">is_mesh_symmetry</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">with_eigenvectors</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
        <span class="n">is_gamma_center</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="p">)</span>

    <span class="c1"># get min, max, step frequency</span>
    <span class="n">frequencies</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">get_mesh_dict</span><span class="p">()[</span><span class="s2">&quot;frequencies&quot;</span><span class="p">]</span>
    <span class="n">freq_min</span> <span class="o">=</span> <span class="n">frequencies</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
    <span class="n">freq_max</span> <span class="o">=</span> <span class="n">frequencies</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
    <span class="n">freq_pitch</span> <span class="o">=</span> <span class="p">(</span><span class="n">freq_max</span> <span class="o">-</span> <span class="n">freq_min</span><span class="p">)</span> <span class="o">/</span> <span class="n">num_dos_steps</span>

    <span class="n">phonon</span><span class="o">.</span><span class="n">run_projected_dos</span><span class="p">(</span>
        <span class="n">freq_min</span><span class="o">=</span><span class="n">freq_min</span><span class="p">,</span> <span class="n">freq_max</span><span class="o">=</span><span class="n">freq_max</span><span class="p">,</span> <span class="n">freq_pitch</span><span class="o">=</span><span class="n">freq_pitch</span>
    <span class="p">)</span>

    <span class="n">dos_raw</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">projected_dos</span><span class="o">.</span><span class="n">get_partial_dos</span><span class="p">()</span>
    <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{</span><span class="n">s</span><span class="p">:</span> <span class="n">dos</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">dos</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">dos_raw</span><span class="p">[</span><span class="mi">1</span><span class="p">])}</span>

    <span class="n">total_dos</span> <span class="o">=</span> <span class="n">PhononDos</span><span class="p">(</span><span class="n">dos_raw</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dos_raw</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">CompletePhononDos</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">total_dos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_phonon_band_structure_from_fc"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_phonon_band_structure_from_fc">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy is required to calculate phonon band structures&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_phonon_band_structure_from_fc</span><span class="p">(</span>
    <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span>
    <span class="n">supercell_matrix</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">force_constants</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">mesh_density</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">100.0</span><span class="p">,</span>
    <span class="o">**</span><span class="n">kwargs</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">PhononBandStructure</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Get a uniform phonon band structure from phonopy force constants.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: A structure.</span>
<span class="sd">        supercell_matrix: The supercell matrix used to generate the force</span>
<span class="sd">            constants.</span>
<span class="sd">        force_constants: The force constants in phonopy format.</span>
<span class="sd">        mesh_density: The density of the q-point mesh. See the docstring</span>
<span class="sd">            for the ``mesh`` argument in Phonopy.init_mesh() for more details.</span>
<span class="sd">        **kwargs: Additional kwargs passed to the Phonopy constructor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        The uniform phonon band structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">structure_phonopy</span> <span class="o">=</span> <span class="n">get_phonopy_structure</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
    <span class="n">phonon</span> <span class="o">=</span> <span class="n">Phonopy</span><span class="p">(</span>
        <span class="n">structure_phonopy</span><span class="p">,</span> <span class="n">supercell_matrix</span><span class="o">=</span><span class="n">supercell_matrix</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
    <span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">set_force_constants</span><span class="p">(</span><span class="n">force_constants</span><span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">run_mesh</span><span class="p">(</span><span class="n">mesh_density</span><span class="p">,</span> <span class="n">is_mesh_symmetry</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">is_gamma_center</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">mesh</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">get_mesh_dict</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">PhononBandStructure</span><span class="p">(</span>
        <span class="n">mesh</span><span class="p">[</span><span class="s2">&quot;qpoints&quot;</span><span class="p">],</span> <span class="n">mesh</span><span class="p">[</span><span class="s2">&quot;frequencies&quot;</span><span class="p">],</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
    <span class="p">)</span></div>


<div class="viewcode-block" id="get_phonon_band_structure_symm_line_from_fc"><a class="viewcode-back" href="../../../pymatgen.io.phonopy.html#pymatgen.io.phonopy.get_phonon_band_structure_symm_line_from_fc">[docs]</a><span class="nd">@requires</span><span class="p">(</span><span class="n">Phonopy</span><span class="p">,</span> <span class="s2">&quot;phonopy is required to calculate phonon band structures&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_phonon_band_structure_symm_line_from_fc</span><span class="p">(</span>
    <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span>
    <span class="n">supercell_matrix</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">force_constants</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">line_density</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">20.0</span><span class="p">,</span>
    <span class="n">symprec</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span>
    <span class="o">**</span><span class="n">kwargs</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">PhononBandStructureSymmLine</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Get a phonon band structure along a high symmetry path from phonopy force</span>
<span class="sd">    constants.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure: A structure.</span>
<span class="sd">        supercell_matrix: The supercell matrix used to generate the force</span>
<span class="sd">            constants.</span>
<span class="sd">        force_constants: The force constants in phonopy format.</span>
<span class="sd">        line_density: The density along the high symmetry path.</span>
<span class="sd">        symprec: Symmetry precision passed to phonopy and used for determining</span>
<span class="sd">            the band structure path.</span>
<span class="sd">        **kwargs: Additional kwargs passed to the Phonopy constructor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        The line mode band structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">structure_phonopy</span> <span class="o">=</span> <span class="n">get_phonopy_structure</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
    <span class="n">phonon</span> <span class="o">=</span> <span class="n">Phonopy</span><span class="p">(</span>
        <span class="n">structure_phonopy</span><span class="p">,</span>
        <span class="n">supercell_matrix</span><span class="o">=</span><span class="n">supercell_matrix</span><span class="p">,</span>
        <span class="n">symprec</span><span class="o">=</span><span class="n">symprec</span><span class="p">,</span>
        <span class="o">**</span><span class="n">kwargs</span>
    <span class="p">)</span>
    <span class="n">phonon</span><span class="o">.</span><span class="n">set_force_constants</span><span class="p">(</span><span class="n">force_constants</span><span class="p">)</span>

    <span class="n">kpath</span> <span class="o">=</span> <span class="n">HighSymmKpath</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="n">symprec</span><span class="p">)</span>

    <span class="n">kpoints</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">kpath</span><span class="o">.</span><span class="n">get_kpoints</span><span class="p">(</span>
        <span class="n">line_density</span><span class="o">=</span><span class="n">line_density</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span>
    <span class="p">)</span>

    <span class="n">phonon</span><span class="o">.</span><span class="n">run_qpoints</span><span class="p">(</span><span class="n">kpoints</span><span class="p">)</span>
    <span class="n">frequencies</span> <span class="o">=</span> <span class="n">phonon</span><span class="o">.</span><span class="n">qpoints</span><span class="o">.</span><span class="n">get_frequencies</span><span class="p">()</span><span class="o">.</span><span class="n">T</span>

    <span class="n">labels_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">([(</span><span class="n">a</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">a</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">kpoints</span><span class="p">)</span> <span class="k">if</span> <span class="n">a</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">PhononBandStructureSymmLine</span><span class="p">(</span>
        <span class="n">kpoints</span><span class="p">,</span> <span class="n">frequencies</span><span class="p">,</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span> <span class="n">labels_dict</span><span class="o">=</span><span class="n">labels_dict</span>
    <span class="p">)</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.phonopy</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>